package cn.chengpengper.shortlink.util;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;

/**
 * @author huchengpeng
 * @version v1.0.0
 * @date 2023/8/21 21:37
 * @description Redis key builder
 */
@Slf4j
public class RedisKeyUtil {
    public static String getCaptchaKey(String keyTemplate, HttpServletRequest request) {
        String ip = CommonUtil.getIpAddr(request);
        String userAgent = request.getHeader("User-Agent");
        String key = String.format(keyTemplate, CommonUtil.MD5(ip + userAgent));
        log.info("CaptchaController | getCaptchaKey | key={}", key);
        return key;
    }
}
